package service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import pojo.Customer;
import service.CustomerManager;

public class CustomerManagerImpl implements CustomerManager{
	private List<Customer> customerlist;
	
	public CustomerManagerImpl(){
		customerlist = new ArrayList<Customer>();
	}
	
	
	@Override
	public synchronized Customer add(Customer c) {
		String id = UUID.randomUUID().toString();
		c.setId(id);
		customerlist.add(c);
		return c;
	}

	@Override
	public synchronized List<Customer> getlist() {
		return customerlist;
	}


	@Override
	public synchronized boolean delete(String id) {
		for(Customer c:customerlist){
			if(c.getId().equals(id)){
				int index=customerlist.indexOf(c);
				customerlist.remove(index);
				return true;
			}
		}
		return false;
	}


	@Override
	public Customer updateCustomer(Customer c) {
		for(Customer cc:customerlist){
			if(cc.getId().equals(c.getId())){
				int index=customerlist.indexOf(cc);
				customerlist.set(index, c);
			}
		}
		return c;
	}
	
}
